package client

import (
	"yunj/app/enum/redisenum"
	"yunj/app/model"
	"yunj/pkg/global"
	"yunj/pkg/yunj/util"
)

type ad struct {
	Service
}

var Ad *ad

// 获取正常已发布的广告
func (a *ad) ItemsByNormalPublish(locationConst int) []*model.Ad {
	var ads []*model.Ad
	res, err := redisenum.KeyByValue(redisenum.KEY_INDEX_AD_ITEMS_BY_LOCATION).SetArgs(locationConst).GetCache(0)
	if err != nil {
		global.Logger.Error("获取正常已发布的广告缓存异常！", err)
		return ads
	}

	ads, err = util.JsonTo[[]*model.Ad](res)
	if err != nil {
		global.Logger.Error("获取正常已发布的广告缓存错误！", err)
	}
	return ads
}
